package demo.excmaputil.util.excmap;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import demo.excmaputil.util.excmap.ExcMapUtil.ExcMapConfig;
import demo.excmaputil.util.excmap.ExcMapUtil.ExcMapRenderer;

/**
 * 银行卡对象转换Map<String,Object>配置
 * 
 * @author jishaocong
 *
 */
public class BankCardExcMapConfig extends ExcMapConfig {
	public static final ExcMapConfig CONFIG = new ExcMapConfig();

	private BankCardExcMapConfig() {
	}

	static {
		/* 渲染器 */
		Map<String, ExcMapRenderer> renderers = new HashMap<String, ExcMapUtil.ExcMapRenderer>();
		ExcMapRenderer cardNum = new ExcMapRenderer() {// 银行卡号
			@Override
			public Object function(Object value, Object entity) {
				StringBuilder sBuilder = new StringBuilder((String) value);
				return "**** **** ****" + sBuilder.substring(sBuilder.length() - 4);
			}
		};
		ExcMapRenderer type = new ExcMapRenderer() {// 类型
			@Override
			public Object function(Object value, Object entity) {
				Integer type = (Integer) value;
				if (type == 0) {
					return "储蓄卡";
				} else if (type == 1) {
					return "信用卡";
				}
				return null;
			}
		};
		renderers.put("cardNum", cardNum);
		renderers.put("type", type);

		/* 只包含字段 */
		Set<String> includeFields = new HashSet<String>();
		includeFields.add("cardNum");
		includeFields.add("bankName");
		includeFields.add("type");
		includeFields.add("validDate");

		/* 日期格式 */
		Map<String, String> dateFormat = new HashMap<String, String>();
		dateFormat.put("validDate", "time");// 时间转换为毫秒数

		CONFIG.setIncludeFields(includeFields);
		CONFIG.setRenderers(renderers);
		CONFIG.setDateFormats(dateFormat);

	}
}
